//
//  spItem.m
//  SoundPill
//
//  Created by 宋鹏鹏 on 15/3/25.
//  Copyright (c) 2015年 宋旭东. All rights reserved.
//

#import "spItem.h"
#import "UIImage+MJ.h"

#define kDeviceHeight [UIScreen mainScreen].bounds.size.height
#define kDeviceWidth  [UIScreen mainScreen].bounds.size.width

#define kTitleScale 0.5
// 设置宽高
#define kMenuItemW kDeviceWidth*0.22
#define kMenuItemH 36

@implementation spItem
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // 1.文字颜色
        [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        self.titleLabel.textAlignment = NSTextAlignmentLeft;
        self.titleLabel.font = [UIFont systemFontOfSize:12];
        
        // 2.设置图标
       // [self setImage:[UIImage imageNamed:@"ic_arrow_down.png"] forState:UIControlStateNormal];
       
        self.imageView.contentMode = UIViewContentModeScaleAspectFit;
        
        // 3.上边的分割线
        UIImage *upImg = [UIImage imageNamed:@"lightgray_h"];
        UIImageView *updivider = [[UIImageView alloc] initWithImage:upImg];
        updivider.bounds = CGRectMake(0, 0, kMenuItemW, 0.5);
        updivider.center = CGPointMake(kMenuItemW/2, 0);
        //[self addSubview:updivider];
        
        // 3.下边的分割线
        UIImage *downImg = [UIImage imageNamed:@"gray_line"];
        UIImageView *downDivider = [[UIImageView alloc] initWithImage:downImg];
        downDivider.bounds = CGRectMake(0,0, kMenuItemW, 1 );
        downDivider.center = CGPointMake(kMenuItemW/2, kMenuItemH-0.5);
        //[self addSubview:downDivider];

        
        // 4.右边的分割线
        //UIImage *img = [UIImage imageNamed:@"separator_topbar_item.png"];
         UIImage *img = [UIImage imageNamed:@"lightgray_s"];
        UIImageView *divider = [[UIImageView alloc] initWithImage:img];
        divider.bounds = CGRectMake(0, 0, 1, kMenuItemH * 0.7);
        divider.center = CGPointMake(kMenuItemW-0.7, kMenuItemH * 0.5);
        //[self addSubview:divider];
        
        self.userInteractionEnabled=NO;
        
//        // 4.选中时的背景  图片会被拉伸
//        [self setBackgroundImage:[UIImage resizedImage:@"slider_filter_bg_normal.png"] forState:UIControlStateSelected];
        
    }
    return self;
}

- (void)setTitle:(NSString *)title
{
    _title = title;
    
    [self setTitle:title forState:UIControlStateNormal];
}

- (void)setFrame:(CGRect)frame
{
    frame.size = CGSizeMake(kMenuItemW, kMenuItemH);
    [super setFrame:frame];
}

- (CGRect)titleRectForContentRect:(CGRect)contentRect
{
    CGFloat h = contentRect.size.height*0.8;
    CGFloat w = contentRect.size.width * kTitleScale;
    return CGRectMake(contentRect.size.width * 0.3+7, contentRect.size.height*0.2, w, h);
}

- (CGRect)imageRectForContentRect:(CGRect)contentRect
{
    CGFloat h = contentRect.size.height*0.8;
    CGFloat w = contentRect.size.width * 0.31;
   
    return CGRectMake(contentRect.size.width * 0.072, contentRect.size.height*0.2, w, h);
}


@end
